
//入口函数：
$(document).ready(function(){
   
   

   

   


    //获取节点
    function $$(ele){
        return document.querySelector(ele);
    }


    //发送AJAx 

    function ajax(param){
        return new Promise(function(resolve,reject){
            //ajax
            let xhr = new XMLHttpRequest();
            xhr.open('get',param.url);
            xhr.send();
            //监听
            xhr.addEventListener('readystatechange',res);
            function res(){
                if(xhr.readyState == 4 && xhr.status == 200)resolve(xhr.response);
            }
    
        })
    }
    var btn = document.getElementById("btn");
    btn.onclick = function(){



        //数据添加
        let  tel = $$('#tel').value;
        // console.log(phone)
        let  pass = $$('#pass').value;
        // console.log(passworld)

        if(!tel || !pass) return;

        //拼接数据

        let  param = `tel=${tel}&pass=${pass}`;

        //发送数据

        ajax({url:'http://localhost/ylf/php/login.php?fn=add&' +param}).then(res=>{
            res = JSON.parse(res);
           
            if(res.stateCode == 200){
                alert('登录成功,即将跳转到首页')
                sessionStorage.setItem("asd",tel);
                // console.log( sessionStorage.getItem("asd"));
                location.href ="http://localhost/ylf/index.html";

            }else{
                alert('登录失败，请重新输入账号')
            }
        });
        
        return;
    }










});
